@echo off

rem - USAGE:
rem -   Copy this script to your application area, probably at the root of your web project
rem -   Modify the svn variable below to point at a valid svn executable
rem -   Run
rem - See the Usage goto tag in the bottom of this script for more usage description, or read the script

rem - Never modify Spectrum.Commons in your application area; note that you'll be deleting it whenever you run this (this is for your own good...)

rem - branch to use (or trunk)
rem - set branch=trunk
set branch=Spectrum.Commons.Standalone

rem - branch path strings
if "%branch%" == "trunk" (
	set branchBS=trunk
	set branchFS=trunk
) else (
	set branchBS=branches\%branch%
	set branchFS=branches/%branch%
)

rem - IMPORTANT: Set this variable to the relative location of svn.exe from this script; a copy is always kept in Spectrum.Commons/Deployment
rem - Yes, an absolute path will work ... for you ... but keep it relative...
set svn=.\..\..\..\..\..\Spectrum.Commons\%branchBS%\Deployment\Subversion.Bin\svn.exe
set svnopt=

if not exist "%svn%" (
  set svn=c:\_build\Subversion.Bin\svn.exe
  set svnopt= --config-dir c:\_build\Subversion.Bin\conf
)

rem - You may change this, but it's not recommended; this is the name of the directory that files will be exported to (relative from the path of this script)
set exportDir=Spectrum.Commons

rem - consider confirming
rem - consider usage output

rem - check that subversion is available first
if not exist %svn% ( goto pathNotFound )

rem - delete existing files
if exist %exportDir% (
	echo Recursively deleting files from directory %exportDir%...
	del /S /Q /A-S-H  %exportDir%\*
) else (
	mkdir %exportDir%
)

rem - build the command
set com=%svn% --force --username svc_webscm --password !@jsja8724jSKhwSAJ!3 %svnopt% --no-auth-cache --non-interactive export 
if not "%~1" == "" (
	set inpath=%~1
	set locpath="%inpath%Spectrum.Commons\%branchBS%\Deployment\CurrentVersion"
	echo Exporting from local working copy at %locpath%
	set com=%com% %locpath%
) else (
	echo Exporting from Subversion Head...
	set com=%com% https://dvmsweb01.spectrum-health.org:8443/svn/Web/Spectrum.Commons/%branchFS%/Deployment/CurrentVersion/ 
) 
set com=%com% Spectrum.Commons
rem echo %com%

rem - execute the command
echo t | %com%

goto end

:pathNotFound
echo Subversion binary path not found! Check your spelling, check the files (you're looking for %svn%).
goto end

:usage
echo Usage: ExportCommons.cmd [workingCopyPath]
echo If WorkingCopyPath is supplied, files will be pulled from your working copy, else from Subversion head
goto end

:end